package cz.proks.easyhelpdesk.gwt.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

import cz.proks.easyhelpdesk.api.model.HelpdeskRole;
import cz.proks.easyhelpdesk.api.model.User;

public class RoleChangeEvent extends GwtEvent<RoleChangeEvent.Handler>{
    
    public final static Type<RoleChangeEvent.Handler> TYPE = new Type<RoleChangeEvent.Handler>();
    
    public static interface Handler extends EventHandler {
        void onRoleChange(RoleChangeEvent event);
    }
    
    private final User user;
    private final HelpdeskRole role;
    
    public RoleChangeEvent(User user, HelpdeskRole role) {
        super();
        this.user = user;
        this.role = role;
    }
    
    public static void fireEvent(HasRoleChangeHandlers source, User user, HelpdeskRole role) {
        source.fireEvent(new RoleChangeEvent(user, role));
    }
    
    public User getMember() {
        return user;
    }
    
    public HelpdeskRole getRole() {
        return role;
    }

    @Override
    public com.google.gwt.event.shared.GwtEvent.Type<Handler> getAssociatedType() {
        return TYPE;
    }

    @Override
    protected void dispatch(Handler handler) {
        handler.onRoleChange(this);
    }    
}
